#include <stdio.h>

int main() {
    unsigned long long a, b, m;
    scanf("%llu %llu %llu", &a, &b, &m);
    // unsigned long long result = ((a % m) * (b % m)) % m;
    // 上述方法不可行，运用循环取余操作
    unsigned long long baseValue = a % m;
    unsigned long long result = 0;
    for (int i = 0; i < b % m; i++) {
        result += baseValue;
        result %= m;
    }
    printf("%llu", result);
}